﻿Public Class SearchTaskTypeForm

    Private Sub SearchTaskTypeForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        GenericAdministrator.loadGrid(dgvSearchTaskType, bdnSearchTaskType, GenericAdministrator.searchDataByFilter(New TaskType()))
        setDataGridViewHeaders()
    End Sub

    Public Sub cargarGrilla()
        Dim query As String
        Dim com As Data.OleDb.OleDbCommand = New Data.OleDb.OleDbCommand
        Dim TABLE As DataTable = New DataTable

        query = "SELECT * "
        query &= "FROM task_type "
        query &= "ORDER BY id"
        DataAccessConnection.openConnection()
        com.Connection = DataAccessConnection.connection
        com.CommandType = CommandType.Text
        com.CommandText = query
        TABLE.Load(com.ExecuteReader)
        Me.dgvSearchTaskType.DataSource = TABLE
        DataAccessConnection.closeConnection()
    End Sub

    Private Sub txtId_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtId.KeyPress
        ViewValidators.isInteger(e)
    End Sub

    Private Sub txtId_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtId.TextChanged

    End Sub

    Private Sub cmdBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBuscar.Click
        Dim id As Integer
        If Me.txtId.Text = Nothing Then
            id = 0
        Else
            id = Convert.ToInt16(Me.txtId.Text)
        End If
        Dim taskType As New TaskType(id, Me.txtNombre.Text, Me.txtDescripcion.Text)
        GenericAdministrator.loadGrid(Me.dgvSearchTaskType, Me.bdnSearchTaskType, GenericAdministrator.searchDataByFilter(taskType))
    End Sub

    Private Sub setDataGridViewHeaders()
        Me.dgvSearchTaskType.Columns(0).HeaderText = "Codigo"
        Me.dgvSearchTaskType.Columns(1).HeaderText = "Nombre"
        Me.dgvSearchTaskType.Columns(2).HeaderText = "Descripcion"
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        Dim opcion As Integer
        opcion = MsgBox("¿Está seguro que desea Eliminar el registro seleccionado?", vbYesNo + vbQuestion + vbDefaultButton2, "Salir")
        If opcion = vbYes Then
            GenericAdministrator.deletedById(New TaskType(Me.dgvSearchTaskType.CurrentRow.Cells(0).Value, Nothing, Nothing))
        End If
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        Dim idSelected As Integer
        idSelected = Me.dgvSearchTaskType.CurrentRow.Cells(0).Value
        Me.Close()
        Dim taskTypeForm As New TaskTypeForm(idSelected)
        taskTypeForm.MdiParent = Me.MdiParent
        taskTypeForm.Show()
    End Sub
End Class